package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.vo.GroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/8/28
 */
@RestController
@RequestMapping("group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @GetMapping
    public List<GroupVO> groupList(){
        List<GroupVO> groupVOS =   groupService.findAll();
        return groupVOS;
    }

    @PostMapping
    public Group addGroup(@RequestBody Group group){
        group.setCreateDate(new Date());
        Group grup =  groupService.addGroup(group);
        return grup;
    }


    @GetMapping("{groupId}")
    public Group getById(@PathVariable Integer groupId ){
        Group group =  groupService.getById(groupId);
        return group;
    }


}
